package hlhj.fhp.tvlib.fragment

import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.google.gson.Gson
import com.lzy.okgo.OkGo
import com.lzy.okgo.callback.StringCallback
import com.lzy.okgo.model.Response
import com.lzy.okgo.request.base.Request
import com.shuyu.gsyvideoplayer.GSYVideoManager
import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack
import com.shuyu.gsyvideoplayer.listener.LockClickListener
import com.shuyu.gsyvideoplayer.utils.OrientationUtils
import com.shuyu.gsyvideoplayer.video.base.GSYVideoPlayer
import com.tenma.ventures.bean.utils.TMSharedPUtil
import hlhj.fhp.tvlib.Contents
import hlhj.fhp.tvlib.R
import hlhj.fhp.tvlib.adapter.FgmHomeTvListAdp
import hlhj.fhp.tvlib.customView.LoadingDialog
import hlhj.fhp.tvlib.javabean.ShowListBean
import hlhj.fhp.tvlib.javabean.TvListBean
import hlhj.fhp.tvlib.utils.TimeUt
import kotlinx.android.synthetic.main.fgm_home_tv.*
import kotlinx.android.synthetic.main.fgm_home_tv.view.*
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap

/**
 * Created by Never Fear   on 2018\9\10 0010.
Never More....
 */
class HomeTvFgm :Fragment() {
    private var isPlay=false;
    private var dow=0;
    private var chooseTime=""
    private lateinit var loadingDialog: LoadingDialog
    private lateinit var  orientationUtils: OrientationUtils
    private lateinit var rootView:View
    private var adp:FgmHomeTvListAdp?=null
    private val datas=ArrayList<String>()
    private val catHash=HashMap<Int,Boolean>()
    private val catDatas=ArrayList<TvListBean.DataBean>()
    private var toDay=1;
    private lateinit var showListAdp:BaseQuickAdapter<ShowListBean.DataBean.ProgramBean,BaseViewHolder>//节目适配器
    private val showListDatas= java.util.ArrayList<ShowListBean.DataBean.ProgramBean>()
    private var url=""
    private var THEMCOLOR="#DF3434"
    private var nid=-1
    private var timmer:Timer?=null
    private var task:TimerTask?=null
    var pp=0
    private lateinit var catAdp:BaseQuickAdapter<TvListBean.DataBean,BaseViewHolder>
    companion object {
        var tvTitle="电视"
    }
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        rootView=inflater.inflate(R.layout.fgm_home_tv,null)
        loadingDialog= LoadingDialog(context!!)

        if (TMSharedPUtil.getTMThemeColor(context)!=null&&TMSharedPUtil.getTMThemeColor(context).isNotEmpty()){
            THEMCOLOR=TMSharedPUtil.getTMThemeColor(context)
        }
        initCatRcy()
        initShowList()
        setTime()
        setListener()
        return rootView

    }

    private fun initShowList(){
        showListAdp=object :BaseQuickAdapter<ShowListBean.DataBean.ProgramBean,BaseViewHolder>(R.layout.tv_showlist_item,showListDatas){
            override fun convert(helper: BaseViewHolder?, item: ShowListBean.DataBean.ProgramBean?) {
                helper?.setText(R.id.itemTime,item?.time)
                helper?.setText(R.id.itemTittle,item?.name)
                val view = helper?.getView<View>(R.id.itemImg)
                if (item?.online==1){
                    view?.visibility=View.VISIBLE
                    helper?.setTextColor(R.id.itemTime,Color.parseColor("#df0f0f"))
                    helper?.setTextColor(R.id.itemTittle,Color.parseColor("#df0f0f"))
                }else{
                    view?.visibility=View.GONE
                    helper?.setTextColor(R.id.itemTime,Color.parseColor("#333333"))
                    helper?.setTextColor(R.id.itemTittle,Color.parseColor("#333333"))
                }
            }
        }
        rootView.recyclerview.adapter=showListAdp
        rootView.recyclerview.layoutManager=LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false)

        timmer=Timer()

        task=object :TimerTask(){
            override fun run() {
                Log.e("fhp","一次")
                rootView.post {
                    reFreshShowList()
                }
            }
        }

        timmer?.schedule(task,0,30000)

    }
    private fun setListener(){
        catAdp.setOnItemClickListener { adapter, view, position ->
            nid=catDatas[position].id
            for (i in 0..catHash.size-1){
                if (i==position){
                    catHash.put(i,true)
                }else{
                    catHash.put(i,false)
                }
            }
            catAdp.notifyDataSetChanged()
            when(dow){
                1->{
                    rootView.btDay7.performClick()
                }
                2->{
                    rootView.btDay1.performClick()

                }
                3->{
                    rootView.btDay2.performClick()

                }
                4->{
                    rootView.btDay3.performClick()

                }
                5->{
                    rootView.btDay4.performClick()

                }
                6->{
                    rootView.btDay5.performClick()

                }
                7->{
                    rootView.btDay6.performClick()

                }
            }
            rootView.gsyPlayer.setUp(catDatas[position].tv_source, false, "")
//                            rootView. gsyPlayer.startButton.performClick()

        }

    }

    private fun initCatRcy(){
        catAdp=object :BaseQuickAdapter<TvListBean.DataBean,BaseViewHolder>(R.layout.home_new_tv_cat_item,catDatas){
            override fun convert(helper: BaseViewHolder?, item: TvListBean.DataBean?) {
                helper?.setText(R.id.itemTittle,item?.channel_name)
                val textView = helper?.getView<TextView>(R.id.itemTittle)
                if (catHash[helper?.adapterPosition]!!){
                    Log.e("fhp","--------------------------设置次1")
                    val drawable = textView?.background as GradientDrawable
                    drawable.setStroke(2,Color.parseColor(THEMCOLOR))
                    textView.background=drawable
                    helper.setTextColor(R.id.itemTittle,Color.parseColor(THEMCOLOR))
                }else{
                    Log.e("fhp","--------------------------设置次2")
                    val drawable = textView?.background as GradientDrawable
                    drawable.setStroke(2,Color.parseColor("#999999"))
                    textView.background=drawable
                }
            }

        }
        rootView.catList.adapter=catAdp
        rootView.catList.layoutManager= LinearLayoutManager(context!!, LinearLayoutManager.HORIZONTAL,false)
        getCat()
    }
    private fun getCat(){
        OkGo.get<String>(Contents.BaseUrl+ Contents.TV_LIST)
                .execute(object : StringCallback(){
                    override fun onStart(request: Request<String, out Request<Any, Request<*, *>>>?) {
                        super.onStart(request)
                        loadingDialog.show()
                    }
                    override fun onSuccess(response: Response<String>?) {
                        rootView.spView.onFinishFreshAndLoad()
                        loadingDialog.dismiss()
                        val listBean = Gson().fromJson(response!!.body(), TvListBean::class.java)
                        if (listBean.code==1){
                            catDatas.addAll(listBean.data)
                            for (i in 0..catDatas.size-1){
                                if (i==0){
                                    catHash.put(i,true)
                                }else{
                                    catHash.put(i,false)
                                }
                            }
                            catAdp.notifyDataSetChanged()
                            url=catDatas[0].tv_source
                            nid=catDatas[0].id

                            getShowList()
                            setPlayer()

                        }
                    }
                })
    }

    private fun getShowList(){
        if (nid==-1)return
        OkGo.get<String>(Contents.BaseUrl + Contents.SHOW_LIST)
                .params("tv_id", nid)
                .params("program_date", chooseTime)
                .execute(object : StringCallback() {
                    override fun onStart(request: Request<String, out Request<Any, Request<*, *>>>?) {
                        super.onStart(request)
                        loadingDialog.show()
                    }
                    override fun onSuccess(response: Response<String>?) {
                        loadingDialog.dismiss()
                        rootView.spView.onFinishFreshAndLoad()
                        val str = response?.body()
                        val listBean = Gson().fromJson(str, ShowListBean::class.java)
                        if (listBean.code==1){

                            /*rootView.gsyPlayer.setUp(listBean.data.tv_source, false, listBean.data.channel_name)
                            rootView. gsyPlayer.startButton.performClick()*/
                            showListDatas.clear()
                            showListDatas.addAll(listBean.data.program)
                            /*for (i in 0..10){
                                *//**
                                 * time : 16:01
                                 * name : 撒打发斯蒂芬
                                 * type : 1
                                 * online : 2
                                 *//*
                                val bean = ShowListBean.DataBean.ProgramBean()
                                bean.time=""
                                bean.online=2;
                                bean.type=""
                                bean.name=""
                                showListDatas.add(bean)
                            }*/
                            showListAdp.notifyDataSetChanged()
                            var p=0;
                            for (i in 0..showListDatas.size-1){
                                if (showListDatas[i].online==1){
                                    p=i
                                    pp=p
                                    Log.e("fhp","I=${i}时，在播放")
                                }
                            }
                            Log.e("fhp","滑动到${p}")
                            val layoutManager = rootView.recyclerview.layoutManager as LinearLayoutManager
                            layoutManager.scrollToPositionWithOffset(p,0)
                        }else{
                            Toast.makeText(context,listBean.msg, Toast.LENGTH_SHORT).show()
                        }
                    }
                    override fun onError(response: Response<String>?) {
                        super.onError(response)

                    }
                })
    }
    private fun reFreshShowList(){
        if (nid==-1)return
        OkGo.get<String>(Contents.BaseUrl + Contents.SHOW_LIST)
                .params("tv_id", nid)
                .params("program_date", chooseTime)
                .execute(object : StringCallback() {
                    override fun onStart(request: Request<String, out Request<Any, Request<*, *>>>?) {
                        super.onStart(request)
                    }
                    override fun onSuccess(response: Response<String>?) {
                        rootView.spView.onFinishFreshAndLoad()
                        val str = response?.body()
                        val listBean = Gson().fromJson(str, ShowListBean::class.java)
                        if (listBean.code==1){

                            /*rootView.gsyPlayer.setUp(listBean.data.tv_source, false, listBean.data.channel_name)
                            rootView. gsyPlayer.startButton.performClick()*/
                            showListDatas.clear()
                            showListDatas.addAll(listBean.data.program)
                            /*for (i in 0..10){
                                *//**
                                 * time : 16:01
                                 * name : 撒打发斯蒂芬
                                 * type : 1
                                 * online : 2
                                 *//*
                                val bean = ShowListBean.DataBean.ProgramBean()
                                bean.time=""
                                bean.online=2;
                                bean.type=""
                                bean.name=""
                                showListDatas.add(bean)
                            }*/
                            showListAdp.notifyDataSetChanged()
                            var p=0;
                            for (i in 0..showListDatas.size-1){
                                if (showListDatas[i].online==1){
                                    p=i
                                    pp=p
                                    Log.e("fhp","I=${i}时，在播放")
                                }
                            }
                            Log.e("fhp","滑动到${p}")
                            val layoutManager = rootView.recyclerview.layoutManager as LinearLayoutManager
                            layoutManager.scrollToPositionWithOffset(p,0)
                        }else{
                            Toast.makeText(context,listBean.msg, Toast.LENGTH_SHORT).show()
                        }
                    }

                    override fun onError(response: Response<String>?) {

                        super.onError(response)

                    }
                })
    }

    private fun setPlayer() {
        rootView.gsyPlayer.setUp(url, false, "")
//        rootView. gsyPlayer.startButton.performClick()

        orientationUtils = OrientationUtils(activity, rootView.gsyPlayer)
        orientationUtils.isEnable = false
        //初始化不打开外部的旋转
        rootView. gsyPlayer.setIsTouchWiget(true);
        //关闭自动旋转
        rootView.gsyPlayer.setRotateViewAuto(false);
        rootView.gsyPlayer.setLockLand(false);
        rootView.gsyPlayer.setShowFullAnimation(false);
        rootView.gsyPlayer.setNeedLockFull(true);
        rootView. gsyPlayer.setVideoAllCallBack(object : GSYSampleCallBack() {
            override fun onPrepared(url: String?, vararg objects: Any?) {
                super.onPrepared(url, *objects)
                orientationUtils.isEnable = true
                isPlay = true
            }

            override fun onQuitFullscreen(url: String?, vararg objects: Any?) {
                super.onQuitFullscreen(url, *objects)
                if (orientationUtils != null) {
                    orientationUtils.backToProtVideo()
                }
            }

            override fun onAutoComplete(url: String?, vararg objects: Any?) {
                super.onAutoComplete(url, *objects)
            }

            override fun onClickStartError(url: String?, vararg objects: Any?) {
                super.onClickStartError(url, *objects)
            }
        })
        rootView.gsyPlayer.setLockClickListener(object : LockClickListener {
            override fun onClick(view: View?, lock: Boolean) {
                if (orientationUtils != null) {
                    //配合下方的onConfigurationChanged
                    orientationUtils.isEnable = !lock
                }
            }
        })
        rootView.gsyPlayer.getTitleTextView().setVisibility(View.GONE);
        rootView.gsyPlayer.getBackButton().setVisibility(View.GONE);

        rootView.gsyPlayer.fullscreenButton.setOnClickListener {
            orientationUtils.resolveByClick()
            rootView.gsyPlayer.startWindowFullscreen(context, false, true)
        }

//        getDetailData()
    }

    private fun setTime() {
        val list = TimeUt.printWeekdays()
        val list2 = TimeUt.printWeekdays2()
        Log.e("fhp","日期1${list.toString()}日期2${list2}")
        rootView.btDay1.setOnClickListener{
            chooseTime=list2[0]
//            getDetailData()
            getShowList()
            rootView.tv1.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_one.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_one.setBackgroundResource(R.drawable.day_choose)

            rootView.tv2.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_two.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_two.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv3.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_three.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_three.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv4.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_four.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_four.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv5.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_five.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_five.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv6.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_six.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_six.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv7.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_seven.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_seven.setBackgroundResource(R.drawable.day_unchoose)
        }
        rootView.btDay2.setOnClickListener{
            chooseTime=list2[1]
//            getDetailData()
            getShowList()
            rootView.tv2.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_two.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_two.setBackgroundResource(R.drawable.day_choose)

            rootView.tv1.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_one.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_one.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv3.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_three.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_three.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv4.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_four.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_four.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv5.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_five.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_five.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv6.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_six.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_six.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv7.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_seven.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_seven.setBackgroundResource(R.drawable.day_unchoose)
        }
        rootView.btDay3.setOnClickListener{
            chooseTime=list2[2]
//            getDetailData()
            getShowList()

            rootView.tv3.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_three.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_three.setBackgroundResource(R.drawable.day_choose)

            rootView.tv1.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_one.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_one.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv2.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_two.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_two.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv4.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_four.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_four.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv5.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_five.setTextColor(resources.getColor(R.color.unChosse))
            rootView. tv_five.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv6.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_six.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_six.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv7.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_seven.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_seven.setBackgroundResource(R.drawable.day_unchoose)
        }
        rootView.btDay4.setOnClickListener{
//            getDetailData()
            chooseTime=list2[3]
            getShowList()

            rootView.tv4.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_four.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_four.setBackgroundResource(R.drawable.day_choose)

            rootView.tv1.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_one.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_one.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv2.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_two.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_two.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv3.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_three.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_three.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv5.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_five.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_five.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv6.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_six.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_six.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv7.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_seven.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_seven.setBackgroundResource(R.drawable.day_unchoose)
        }
        rootView.btDay5.setOnClickListener{
//            getDetailData()
            chooseTime=list2[4]
            getShowList()

            rootView.tv5.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_five.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_five.setBackgroundResource(R.drawable.day_choose)

            rootView.tv1.setTextColor(resources.getColor(R.color.unChosse))
            rootView. tv_one.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_one.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv2.setTextColor(resources.getColor(R.color.unChosse))
            rootView. tv_two.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_two.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv3.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_three.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_three.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv4.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_four.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_four.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv6.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_six.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_six.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv7.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_seven.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_seven.setBackgroundResource(R.drawable.day_unchoose)
        }
        rootView.btDay6.setOnClickListener{
            chooseTime=list2[5]
//            getDetailData()
            getShowList()

            rootView.tv6.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_six.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_six.setBackgroundResource(R.drawable.day_choose)

            rootView.tv1.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_one.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_one.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv2.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_two.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_two.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv3.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_three.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_three.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv4.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_four.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_four.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv5.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_five.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_five.setBackgroundResource(R.drawable.day_unchoose)

            rootView. tv7.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_seven.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_seven.setBackgroundResource(R.drawable.day_unchoose)
        }
        rootView.btDay7.setOnClickListener{
            chooseTime=list2[6]
//            getDetailData()
            getShowList()

            rootView.tv7.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_seven.setTextColor(resources.getColor(R.color.choose))
            rootView.tv_seven.setBackgroundResource(R.drawable.day_choose)

            rootView.tv1.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_one.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_one.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv2.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_two.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_two.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv3.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_three.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_three.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv4.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_four.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_four.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv5.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_five.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_five.setBackgroundResource(R.drawable.day_unchoose)

            rootView.tv6.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_six.setTextColor(resources.getColor(R.color.unChosse))
            rootView.tv_six.setBackgroundResource(R.drawable.day_unchoose)
        }
        rootView.tv_one.text = list[0]
        rootView.tv_two.text = list[1]
        rootView. tv_three.text = list[2]
        rootView. tv_four.text = list[3]
        rootView.tv_five.text = list[4]
        rootView.tv_six.text = list[5]
        rootView.tv_seven.text = list[6]

        dow = Calendar.getInstance().get(Calendar.DAY_OF_WEEK)
        when(dow){
            1->{
                chooseTime=list2[6]
                toDay=1
                rootView.btDay7.performClick()
            }
            2->{
                toDay=2
                chooseTime=list2[0]
                rootView. btDay1.performClick()

            }
            3->{
                toDay=3
                chooseTime=list2[1]
                rootView. btDay2.performClick()

            }
            4->{
                toDay=4
                chooseTime=list2[2]
                rootView.btDay3.performClick()

            }
            5->{
                toDay=5
                chooseTime=list2[3]
                rootView.btDay4.performClick()

            }
            6->{
                toDay=6
                chooseTime=list2[4]
                rootView.btDay5.performClick()

            }
            7->{
                toDay=7
                chooseTime=list2[5]
                rootView.btDay6.performClick()

            }

        }


    }

    override fun onPause() {
        getCurPlay().onVideoPause()
        super.onPause()
    }

    override fun onResume() {
        getCurPlay().onVideoResume()
        super.onResume()
    }

    override fun onDestroy() {
        super.onDestroy()
        getCurPlay().release()
        timmer?.cancel()
        if (orientationUtils!=null){
            orientationUtils.releaseListener()
        }
    }

    private fun getCurPlay(): GSYVideoPlayer {
        return if (rootView.gsyPlayer.fullWindowPlayer != null) {
            rootView.gsyPlayer.fullWindowPlayer
        } else rootView.gsyPlayer
    }

}